﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

using AKMII.DMRA.Business.Rule;

namespace AKMII.DMRA.DataLoader
{
    public class Config
    {
        Dictionary<string, string> filesToBeDownload = new Dictionary<string, string>();

        public Dictionary<string, string> FilesToBeDownload
        {
            get { return filesToBeDownload; }
            set { filesToBeDownload = value; }
        }

        /// <summary>
        /// constructor, also list the files will be download from ftp
        /// </summary>
        public Config()
        {
            try
            {
                List<string> files = FtpUtils.ListDirectory(SystemConfiguration.CommonSetting.DownloadFtp,
                    SystemConfiguration.CommonSetting.FtpUserName, SystemConfiguration.CommonSetting.FtpPassword);

                string ftpAddress = SystemConfiguration.CommonSetting.DownloadFtp;

                foreach (string file in files)
                {
                    if (!ftpAddress.EndsWith(Constants.SLASH))
                    {
                        ftpAddress += Constants.SLASH;
                    }

                    StringBuilder sb = new StringBuilder();
                    sb.Append(ftpAddress);
                    sb.Append(file);
                    filesToBeDownload.Add(sb.ToString(), file);
                }
            }
            catch (Exception e)
            {
                Logger.Info(e.Message);
            }
        }

    }
}
